//
//  AnimationTimingDemo.swift
//  SwiftUIDemo
//
//  Created by Tilt Wang on 2025/6/28.
//

import SwiftUI

struct AnimationTimingDemo: View {
    
    @State var isAnimated: Bool = false
    
    let timing: Double = 10.0
    
    var body: some View {
        
        VStack {
            Button("Button") {
                isAnimated.toggle()
            }
            RoundedRectangle(cornerRadius: 20)
                .frame(width: isAnimated ? 350 : 50, height: 100)
                .animation(
                    .spring(
                        response: 0.5, //响应时长
                        dampingFraction: 0.7, //弹簧 阻尼洗漱
                        blendDuration: 1.0
                    )
                    , value: isAnimated)
//                .animation(.spring(), value: isAnimated)
//                .animation(Animation.linear(duration: timing))
//            RoundedRectangle(cornerRadius: 20)
//                .frame(width: isAnimated ? 350 : 50, height: 100)
//                .animation(Animation.easeIn(duration: timing))
//            RoundedRectangle(cornerRadius: 20)
//                .frame(width: isAnimated ? 350 : 50, height: 100)
//                .animation(Animation.easeOut(duration: timing))
//            RoundedRectangle(cornerRadius: 20)
//                .frame(width: isAnimated ? 350 : 50, height: 100)
//                .animation(Animation.easeInOut(duration: timing))
        }
        
    }
}

#Preview {
    AnimationTimingDemo()
}
